package com.benmei.waijiaojun.fragment;

import android.support.v4.app.Fragment;

import java.util.HashMap;
import java.util.Map;

/**
 * 作者：husunxing
 * 创建日期：2017/11/28.
 * 邮箱：husunxing@outlook.com
 * 描述：Fragment工厂类
 */
public class FragmentFactory {

    private static Map<Integer, Fragment> mFragments = new HashMap<>();

    public static Fragment createFragment(int position) {
        Fragment fragment = null;
        fragment = mFragments.get(position);
        if(fragment == null) {
            switch (position){
                case 0:
                    fragment = new HomeFragment();
                    break;
                case 1:
                    fragment = new MastersCourseFragment();
                    break;
                case 2:
                    fragment = new KnowledgeBaseFragment();
                    break;
                case 3:
                    fragment = new MessageFragment();
                    break;
                case 4:
                    fragment = new MineFragment();
                    break;
            }
            if(fragment != null) {
                mFragments.put(position, fragment);
            }
        }
        return fragment;

    }
}
